from django.db import models
from django.contrib.auth.models import AbstractUser
# 需要继承基类，就需要先导入基础类
from myutiles.base_model import BaseModel
# Create your models here.

# 角色表
class Role(BaseModel):
    """
    角色名称
        普通用户、管理员、vip
    """
    role_name = models.CharField(max_length=30)

    class Meta:
        # db_table 来指定起名儿
        db_table = 'role'
    # 这里需要重写方法
    def __str__(self):
        return self.role_name


class User(BaseModel,AbstractUser):
    """
    继承django自带的user表
    """
    icon = models.ImageField(upload_to='static')
    phone = models.CharField(max_length=11)


    class Meta:
        db_table = 'user'

    def __str__(self):
        return self.username



# JWT json web token
"""
用户token
"""
class UserToken(BaseModel):
    token = models.CharField(max_length=300)
    user = models.OneToOneField(User,on_delete=models.CASCADE)

    class Meta:
        db_table = 'usertoken'

    def __str__(self):
        return self.token



class OpenUser(models.Model):
    TYPE_CHOICES = ((1, "微博"), (2, "微信"), (3, "QQ"))
    uid = models.CharField(max_length=20)
    type = models.SmallIntegerField(choices=TYPE_CHOICES)
    user = models.ForeignKey(User,on_delete=models.CASCADE,null=True)

    class Meta:
        db_table = "open_users"
